package com.MedDroid.task;

import android.os.AsyncTask;
import android.view.View;
import com.MedDroid.MainApp;
import com.MedDroid.activity.MainMenuActivity;
import com.MedDroid.control.AuthenticationControl;
import com.MedDroid.entities.Permissions;

import java.lang.ref.WeakReference;

/**
 * Created with IntelliJ IDEA.
 * User: Romen
 * Date: 02/12/13
 * Time: 2:44 PM
 * Description:
 */
public class LoadMainMenuTask extends AsyncTask<Void, Void, Void>
{
	AuthenticationControl AuthenticationC;
	WeakReference<MainMenuActivity> MainMenu;
	Permissions Access;

	public LoadMainMenuTask(AuthenticationControl Auth, MainMenuActivity MainMenu)
	{
		AuthenticationC = Auth;
		this.MainMenu = new WeakReference<MainMenuActivity>(MainMenu);
	}

	@Override
	protected Void doInBackground(Void... voids)
	{
		Access = AuthenticationC.getAccess();
		return null;
	}

	@Override
	protected void onPostExecute(Void V)
	{
		MainMenuActivity Menu = MainMenu.get();
		//Remove buttons
		if (!Access.getPermission(Permissions.PAddUser) && !Access.getPermission(Permissions.PModifyUser))
		{
			MainApp.log("Hide Manage Users Button.");
			Menu.BtnManageUsers.setVisibility(View.GONE);
		}
	}
}
